<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="/authtaglib" prefix="auth" %>
<!DOCTYPE html>
<html>
<head>
<title>邮件推送</title>
<style type="text/css">
.replystyle{
 margin: 0 auto;
 width: '80%';
}
.replystyle li{
margin-top:3px;
text-align: center;
font-size: 18px;
}
</style>
<jsp:include page="/include.jsp"/>
<script type="text/javascript">
//新增数据源配置信息窗口

function doAddDatasource() {

    $('<div id="addDiv"/>').dialog({
        href: '${pageContext.request.contextPath}/message/messageAction!toAddPage.action',
        top: 100,
        width: 550,
        modal: true,
        title: '新增信息',
        buttons: [
            {
                id: 'btnSave',
                text: '保存',
                iconCls: '',
                handler: function () {
                   // selectValue();
                    var d = $(this).closest('.window-body');
                    $('#form').form('submit', {
                        url: '${pageContext.request.contextPath}/message/messageAction!adminSendMessage.action',
                        onSubmit: function () {
                            if ($(this).form("validate")) {
                                $.messager.progress({title: '提示', text: '正在处理，请稍候 ....'});
                            } else {
                                return false;
                            }
                        },
                        success: function (result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.returnFlag) {
                                   $('#datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                //显示提示信息
                                $.messager.show({
                                    title: '提示',
                                    msg: r.returnMsg
                                });
                               
                            } catch (e) {
                            }
                            $.messager.progress('close');
                        }
                    });
                }
            },
            {
                id: 'btnCancle',
                text: '取消',
                iconCls: '',
                handler: function () {
                    $(this).closest('.window-body').dialog('destroy');
                    location.reload();
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
            //刷新主列表
           location.reload();
        }
    });
}
function doAddMsg() {
    $('<div id="addDiv"/>').dialog({
        href: '${pageContext.request.contextPath}/message/messageAction!toAddMsgPage.action',
        top: 100,
        width: 520,
        modal: true,
        title: '自定义信息',
        buttons: [
            {
                id: 'btnSave',
                text: '保存',
                iconCls: '',
                handler: function () {
                    var d = $(this).closest('.window-body');
                    $('#form').form('submit', {
                        url: '${pageContext.request.contextPath}/message/messageAction!toAddMsg.action',
                        onSubmit: function () {
                            if ($(this).form("validate")) {
                                $.messager.progress({title: '提示', text: '正在处理，请稍候 ....'});
                            } else {
                                return false;
                            }
                        },
                        success: function (result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.returnFlag) {
                               //     $('#datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                //显示提示信息
                                $.messager.show({
                                    title: '提示',
                                    msg: r.returnMsg
                                });
                            } catch (e) {
                            }
                            $.messager.progress('close');
                        }
                    });
                }
            },
            {
                id: 'btnCancle',
                text: '取消',
                iconCls: '',
                handler: function () {
                    $(this).closest('.window-body').dialog('destroy');
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
            //刷新主列表
         //   $('#datagrid').datagrid('reload');
        }
    });
}



//批量删除
function doBatchDelete() {
    var rows = $('#datagrid').datagrid('getChecked');
    if (rows.length <= 0) {
        $.messager.alert('提示', '没有选择任何记录');
    } else {
        var itemIds = [];
        $.each(rows, function (i, item) {
            itemIds.push(item.msgId);
        });
        $.messager.confirm('删除确认', '是否确定删除选中记录？', function (r) {
            if (r) {
                $.ajax({
                    url: '${pageContext.request.contextPath}/message/messageAction!delete.action',
                    async: false,
                    data: {ids: itemIds.join(",")},
                    dataType: "json",
                    success: function (result) {
                        $.messager.show({title: '提示', msg: result.returnMsg});
                        if (result.returnFlag) {
                            //刷新主列表
                            $('#datagrid').datagrid('reload');
                        }
                    }
                });
            }
        });
    }
}

//执行查询
function doQuery() {
    if ($("#datasource_query_form").form("validate")) {
        $("#datagrid").datagrid('options').queryParams = serializeObject($('#datasource_query_form')); //把查询条件赋值给datagrid内部变量
        $("#datagrid").datagrid('load'); //重新加载
    }
}
//重置查询条件
function doReset() {
    $('#datasource_query_form').form('reset');
}
//页面加载完后响应 onReady
$(function () {
    //查询按纽绑定事件
    $('#btnQuery').bind('click', doQuery);
    //重置按纽绑定事件
    $('#btnReset').bind('click', doReset);
    //初始化主列表
    $('#datagrid').datagrid({
        url: '${pageContext.request.contextPath}/messageAction!getAllDatasourceList.action',
        fit: true,
        border: false,
        fitColumns: true,
        pagination: true,
        pageList: [30],
        rownumbers: false,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
				{field: 'msgId', checkbox: true},
                {field: 'msgCreateUser', title: '创建人',align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'msgTitle', title: '标题', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'msgCreateTime', title: '创建时间', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
               // {field: 'silent', title: '是否静默', align: 'left', formatter: function (value, rowData, rowIndex) {
                //	if (!value) {return '--'}
                //	return value == '1'?'静默':'不静默';
               // }},
                {field: 'validity', title: '有效期限',align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'msgContent', title: '消息内容', align: 'left', formatter: function (value, rowData, rowIndex) {return value;}},
                {field: 'replyContent', title: '回复内容', align: 'left', formatter: function (value, rowData, rowIndex) {    
                               var msgId=rowData.msgId;    
                            //   alert("------"+msgId);     
                  $.ajax({
                     url: '${pageContext.request.contextPath}/message/messageAction!getRepllyJSON.action',
                     async: false,
                     data: {msgId: msgId},
                     dataType: "json",
                     success: function (result) {
                    if(result.length > 0){
                     	msgreply=result[0].text;
            	    return msgreply; 	 	
                     }else{
            	      msgreply="暂无回复";
            	      return msgreply;
                     }
                     }
                       });
                       return msgreply;}},
                {field: 'novll', title: '人员操作', align: 'left', formatter: function (value, rowData, rowIndex) {
                	var html = "";
                    html += '<span  style="cursor:pointer" onclick="getReplyList(\'' + rowData.msgId + '\',\'' + rowData.msgTitle + '\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="查看" alt="查看"/>查看回复&nbsp;&nbsp;</span>';
                    return html;
                }}
            ]
        ],
        toolbar: '#datagrid_toobar'
    });
    /**
    $('#search_select_deviceType').combobox({
        url:'${pageContext.request.contextPath}/messageAction!getDeviceTypeSelectData.action',
        valueField:'id',
        textField:'name',
        editable:false
    });*/
});
function getReplyList(msgId,title){
    
	 //alert("---"+msgId);
	  
	$.ajax({
        url: '${pageContext.request.contextPath}/message/messageAction!getRepllyJSON.action',
        async: false,
        data: {msgId: msgId},
        dataType: "json",
        success: function (result) {
            if(result.length > 0){
            	var content = "<ul class='replystyle'>";
            	for(var i=0; i<result.length;i++){
            		
            		content+="<li>"+result[i].empName+":&nbsp;"+result[i].text+"<li/>";
            	}
            	content+="</ul>";
            	var existDialog=$("#showDiv").dialog();
            	if(existDialog[0]){
            		return;
            	}
            	$('<div id="showDiv"/>').dialog({
            		top:130,
                    width: 400,
                    height:80,
                    modal: false,
                    content:content,
                    title: title,
                    onClose:function(){
                    window.location.reload();
                      }
                });
            }else{
            	 $.messager.show({title: '提示', msg: "暂无回复!"});
            }
        }
    });
}

function close(){
window.location.reload();
}
</script>
</head>
<body class="easyui-layout">
<form id="datasource_query_form" method="post">
    <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="30%">
            <tr>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename">姓&emsp;&emsp;名：</label>
                    <input type="text" id="datasource_datsourcename" name="name" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename">&emsp;关键字：</label>
                    <input type="text" id="datasource_datsourcename" name="keyWord" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                	&emsp;
                </td>
            </tr>
              <tr>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label >开始时间：</label>
                    <input id="start" name="start" type="text" class="easyui-datebox">&emsp;
                  </td>
                  <td style="width:1%;text-align:left;" nowrap="nowrap">
                     <label >结束时间：</label>
                    <input id="end" name="end" type="text" class="easyui-datebox">
                </td>
                <td style="width:30%;text-align:left;padding-left: 30px;" nowrap="nowrap">
                    <input type="button" id="btnQuery" value="查 询" class="search_btn"/>
                    <input type="button" id="btnReset" value="重 置" class="reset_btn"/>
                </td>
                
            </tr>
        </table>
    </div>
    <div data-options="region:'center'" style="border-top:none">
        <table id="datagrid"></table>
        <div id="datagrid_toobar" class="etl_panel_title">
             <auth:button authUrl="message/messageAction!addmsg.action">
                <a href="javascript:void(0);" onclick="doAddDatasource()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
            
            <div class="datagrid-btn-separator"></div>
            
                <a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-remove',plain:true" style="float:left;">批量删除</a>
          
            
           <div class="datagrid-btn-separator"></div>
                <a href="javascript:void(0);" onclick="doAddMsg()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true"style="float:left;">自定义信息</a>
            </auth:button>
        </div>
    </div>
</form>
</body>
</html>

